'''
@Descripttion: 多数元素
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-05-15 11:32:19
LastEditTime: 2025-05-15 11:40:57
'''

class Solution:

    # 摩尔投票法 前提是大于 n/2 的元素
    def majorityElement(self, nums: list[int]) -> int:
        votes = 0
        for num in nums:
            if votes == 0:
                x = num
            
            if num == x:
                votes += 1
            else:
                votes -= 1

        
        return x


if __name__ == "__main__":

    nums = [3,2,3]
    sol = Solution()
    res = sol.majorityElement(nums)
    print(res)
